﻿using System;
using System.Net;

namespace Xfs
{
	public class XfsActorMessageSenderComponent : XfsComponent
	{
		public XfsActorMessageSender Get(long actorId, string client = "客户端使用")
		{
			if (actorId == 0)
			{
				throw new Exception($"actor id is 0");
			}

			//IPEndPoint ipEndPoint = XfsStartConfigComponent.Instance.GetInnerAddress(XfsIdGeneraterHelper.GetAppId(actorId));
			//IPEndPoint ipEndPoint = XfsStartConfigComponent.Instance.GetInnerAddress(actorId);
			//XfsActorMessageSender actorMessageSender = new XfsActorMessageSender(actorId, ipEndPoint);

			XfsSession? session = XfsGame.XfsSence.GetComponent<XfsNetInnerComponent>().Client;

			XfsActorMessageSender actorMessageSender = new XfsActorMessageSender(actorId, session);

			return actorMessageSender;
		}

		public XfsActorMessageSender Get(long actorId , long instanceid)
		{
			if (actorId == 0)
			{
				throw new Exception($"actor id is 0");
			}

			//IPEndPoint ipEndPoint = XfsStartConfigComponent.Instance.GetInnerAddress(XfsIdGeneraterHelper.GetAppId(actorId));
			//IPEndPoint ipEndPoint = XfsStartConfigComponent.Instance.GetInnerAddress(actorId);
			//XfsActorMessageSender actorMessageSender = new XfsActorMessageSender(actorId, ipEndPoint);

			XfsSession? session = XfsGame.XfsSence.GetComponent<XfsNetSocketComponent>().Get(instanceid);			

			XfsActorMessageSender actorMessageSender = new XfsActorMessageSender(actorId, session);

			return actorMessageSender;
		}

	}
}
